@damourlabs/euro-clinical-trials
Version:
A Nuxt 3 application for visualizing and managing clinical trials data in Europe, built with modern web technologies.
46 lines (36 loc) • 1.24 kB
text/typescript
import type { Site } from "~/server/database/schema"
import type { ServerResponse } from "~/models/utils"
import { useDb, tables, eq } from "~/server/utils/drizzle"
import { z } from "zod"
export default defineEventHandler(async (event) => {
const db = useDb()
const { data, success, error } = await getValidatedRouterParams(event, z.object({
id: z.string().uuid()
}).spa)
if (!success) {
throw createError({
statusCode: 400,
statusMessage: 'Trial ID is required',
data: error
})
}
const { id } = data
// First verify trial exists
const trial = await db.select().from(tables.trials).where(eq(tables.trials.uuid, id)).limit(1)
if (!trial || trial.length === 0) {
throw createError({
statusCode: 404,
statusMessage: 'Trial not found'
})
}
// Get all sites for this trial
const sites = await db.select().from(tables.sites).where(eq(tables.sites.trialUuid, id))
const response: ServerResponse<Site[]> = {
status: 'success',
statusCode: 200,
statusText: 'OK',
message: 'Trial sites retrieved successfully',
data: sites
}
return response
})